<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="机关办公"></uni-navbar></view>

		<view class="banner"><u-swiper :list="swiperList" :effect3d="true" :title="true" mode="none" height="280" @click="swiperClick"></u-swiper></view>
		<view class="container">
			<u-row class="link-box" gutter="0" align="top">
				<u-col span="3" v-if="$sysMenus('kqdk_m')">
					<navigator hover-class="none" class="link-item" url="/pagesB/sign/clock_in">
						<image src="/static/img/icon_82.png" mode="aspectFill"></image>
						考勤打卡
					</navigator>
				</u-col>
				<u-col span="3" v-if="$sysMenus('qjsq')">
					<navigator hover-class="none" class="link-item" url="/pagesB/oa/add_no1?tabs=0">
						<image src="/static/img/icon_83.png" mode="aspectFill"></image>
						请假申请
					</navigator>
				</u-col>
				<u-col span="3" v-if="$sysMenus('ycsq')">
					<navigator hover-class="none" class="link-item" url="/pagesB/oa/add_no2?tabs=0">
						<image src="/static/img/icon_85.png" mode="aspectFill"></image>
						用餐申请
					</navigator>
				</u-col>
				<u-col span="3" v-if="$sysMenus('ccsq')">
					<navigator hover-class="none" class="link-item" url="/pagesB/oa/add_no3?tabs=0">
						<image src="/static/img/icon_86.png" mode="aspectFill"></image>
						出差申请
					</navigator>
				</u-col>
				<u-col span="3" v-if="$sysMenus('sp')">
					<navigator hover-class="none" class="link-item" url="/pagesB/oa/list_dispose">
						<image src="/static/img/icon_87.png" mode="aspectFill"></image>
						待我审批
					</navigator>
				</u-col>
				<u-col span="3" v-if="$sysMenus('rcgl')">
					<navigator hover-class="none" class="link-item" url="/pagesB/oa/list_no4">
						<image src="/static/img/icon_84.png" mode="aspectFill"></image>
						我的日程
					</navigator>
				</u-col>
			</u-row>

			<block v-if="$sysMenus('rcgl')">
				<view class="h2-row">
					<view class="h2-title">待办事项</view>
					<navigator hover-class="none" class="h2-col" url="/pagesB/oa/add_todo">
						<u-icon name="plus" color="#666" size="28"></u-icon>
						添加事项
					</navigator>
				</view>
				<view class="list-box" :class="loading == 'nodata' ? 'nodata' : ''">
					<view class="list-info_03" v-for="(item, index) of infoList" :key="item.id" @click="navTo(item)">
						<view class="right-type"><u-icon name="error-circle-fill" :color="colorMap[item.type]" size="32"></u-icon></view>
						<view class="info-title clamp" v-html="item.content"></view>
						<view class="info-btm">
							<view class="left-name">{{ item.typeLabel }}</view>
							<view class="left-time">{{ item.createTime | parseTime('{y}-{m}-{d}') }}</view>
						</view>
					</view>

					<view v-if="loading == 'nodata'"><image class="image" src="/static/result-img/no-record.png" mode="widthFix"></image></view>
				</view>
			</block>
		</view>

		<view v-if="false && vacate"></view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			swiperList: [],
			colorMap: {
				0: '#303133',
				1: '#ff3333',
				2: '#0099ff',
				3: '#ff9900',
				4: '#19be6b'
			},
			scrollTop: 0,

			infoList: [],

			vacate: {
				status: '',
				type: '',
				userId: '',
				clientCode: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData();
		this.getBanner();
	},
	onShow() {
		this.loadData('refresh');
	},
	//下拉刷新
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		getBanner() {
			this.swiperList = uni.getStorageSync('swiperList');
		},
		swiperClick(index) {
			// this.current = index;
			if (this.swiperList[index].id) {
				uni.navigateTo({
					url: '/pagesA/banner/detail?id=' + this.swiperList[index].id
				});
			}
		},
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.userId = this.userInfo.sysUser.id;
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.vacate.userId = this.userInfo.sysUser.id;
				this.vacate.clientCode = this.userInfo.sysUser.clientCode;

				this.pageNum = 1;
				this.pageSize = 10;

				try {
					uni.authorize({
						scope: 'scope.userLocation',
						success: (res) => {
							console.log('位置授权成功', res);
						}
					});
				} catch (e) {
					//TODO handle the exception
				}
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.vacate.type == '0') {
				this.vacate.type = '';
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				oaAttndTodo: this.vacate
			};
			this.$request('/oaAttndTodo/oa-attnd-todo/list', data).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.infoList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.infoList = this.infoList.concat(res.data.records);
				this.loaded = true;
				if (this.infoList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pagesB/oa/add_todo?id=' + item.id
			});
		}
	}
};
</script>

<style lang="scss">
.container {
	background-color: #fff;
}

.link-box {
	margin-bottom: 0;
	padding: 30rpx 0 0;

	.link-item {
		padding-bottom: 30rpx;
		min-height: inherit;
		font-size: 13px;
	}

	image {
		margin-bottom: 20rpx;
		width: 80rpx;
		height: 80rpx;
	}
}

.list-box {
	padding-bottom: 60rpx;
}

.nodata {
	width: 100%;
	padding-top: 60rpx;
	padding-bottom: 60rpx;

	.image {
		width: 100%;
		display: block;
	}
}
</style>
